package com.zhouk.ams.wx.menu;

import com.zhouk.ams.constants.RequestMethod;
import com.zhouk.ams.wx.AccessTokenInfo;
import com.zhouk.ams.wx.constants.WxUrl;
import com.zhouk.ams.wx.utils.NetworkHelper;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * Create By Zhouke on 2017/10/24
 */
public class MenuHandler {

    /**
     * 返回结果
     * 正确时的返回JSON数据包如下：
     * {"errcode":0,"errmsg":"ok"}
     * 错误时的返回JSON数据包如下（示例为无效菜单名长度）：
     * {"errcode":40018,"errmsg":"invalid button name size"}
     * @return
     */
    public JSONObject createMenu() throws JSONException {
        NetworkHelper netHelper = new NetworkHelper();
        String url = String.format(WxUrl.CREATE_MENU_URL, AccessTokenInfo.accessToken);

        String data = null;
        //此请求为https的get请求，返回的数据格式为{"access_token":"ACCESS_TOKEN","expires_in":7200}
        JSONObject result = NetworkHelper.httpRequest(url, RequestMethod.POST,data);

        return result;
    }
}
